#include<iostream>
#include<hiredis/hiredis.h>
#include<sw/redis++/redis++.h>
using namespace std;
using namespace sw::redis;

void typePrint(redisReply* ret);

int main()
{
    redisContext* cont = redisConnect("127.0.0.1",6379);
    if(cont->err != 0)
    {
        printf("connect redis err\n");
        puts(cont->errstr);
    }
    redisReply* ret = (redisReply*)redisCommand(cont,"select 1");
    typePrint(ret);
    freeReplyObject(ret);

    ret = (redisReply*)redisCommand(cont,"set v1 value1");
    typePrint(ret);
    freeReplyObject(ret);


    ret = (redisReply*)redisCommand(cont,"get v1");
    typePrint(ret);
    puts(ret->str);
    freeReplyObject(ret);

    redisFree(cont);


    return 0;
}





void typePrint(redisReply* ret)
{
    if(ret->type == REDIS_REPLY_STRING)
        cout<<"type is string\n";
    else if(ret->type == REDIS_REPLY_ARRAY)
        cout<<"type is array\n";
    else if(ret->type == REDIS_REPLY_INTEGER)
        cout<<"type is integer\n";
    else if(ret->type == REDIS_REPLY_NIL)
        cout<<"type is NULL\n";
    else if(ret->type == REDIS_REPLY_STATUS)
        cout<<"type is status ok\n";
    else if(ret->type == REDIS_REPLY_ERROR)
        cout<<"type is ERROR\n";
}